package com.ffapp.demo.home;

import android.app.Activity;
import android.graphics.Rect;
import android.os.Bundle;

import androidx.core.widget.NestedScrollView;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.ffapp.demo.R;
import com.ffapp.demo.basis.BasisActivity;
import com.ffapp.demo.basis.BasisApp;
import com.ffapp.demo.basis.Constants;
import com.ffapp.demo.bean.BasisBean;
import com.ffapp.demo.bean.HomeAppGroupListBean;
import com.ffapp.demo.bean.HomeGrideListBean;
import com.ffapp.demo.bean.HomeGrideListData;

import java.util.Collections;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import my.DialogUtils;
import my.LogUtil;
import my.http.MyHttpListener;
import my.http.MyHttpUtils;
import my.http.MyParams;

/**
 * 用户权限内的所有应用
 */
public class HomeAppActivity extends BasisActivity {


    @BindView(R.id.recyclerview)
    RecyclerView mRecyclerView;
    @BindView(R.id.recyclerview_small)
    RecyclerView recyclerview_small;
    @BindView(R.id.recyclerview_all)
    RecyclerView recyclerview_all;
    private MyAdapterList mAdapter;
    private MyAdapterListSmall mAdapterSmall;
    private HomeGrideListBean mListBean;
    private HomeGrideListBean mListBeanSearch;
    private HomeGrideListBean mListBeanOrg;
    private HomeAppGroupListBean mGroupListBean;
    private AppAllListAdapterList mAdapterAllList;
    boolean isEditMode = false;
    boolean isSearchMode = false;
    @BindView(R.id.edit_search)
    EditText edit_search;
    @BindView(R.id.text_myapp)
    TextView text_myapp;
    @BindView(R.id.text_allapp)
    TextView text_allapp;
    @BindView(R.id.scrollView)
    NestedScrollView scrollView;
    @BindView(R.id.view_bottom_text_zone)
    View view_bottom_text_zone;

    boolean isSpand = false;

    @Override
    public void initViews() {
//        super.initViews();
        setContentView(R.layout.home_app_activity);
        GridLayoutManager layoutManager = new GridLayoutManager(mContext, 5);
        mRecyclerView.setLayoutManager(layoutManager);

        recyclerview_all.setLayoutManager(new LinearLayoutManager(mContext));
        RecyclerView.LayoutManager layoutManagerSmall = new LinearLayoutManager(mContext, RecyclerView.HORIZONTAL, false);
        recyclerview_small.setLayoutManager(layoutManagerSmall);
        recyclerview_small.addItemDecoration(new ItemLeftDecoration(-20));
        ItemTouchHelper mItemTouchHelper = new ItemTouchHelper(mItemTouchCallBack);
        mItemTouchHelper.attachToRecyclerView(mRecyclerView);

    }

    @Override
    public void initData(Bundle savedInstanceState) {
//        super.initData(savedInstanceState);


        setTitle("全部应用");
        mListBean = new HomeGrideListBean();
        setListView();
        getListMine();
        setTitleLeftButton(null);
        getWarnUnReadCount();

        edit_search.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                search();
            }
        });
    }

    @OnClick(R.id.img_search)
    void search() {
        if (isEditMode) return;
        String searchkey = edit_search.getText().toString().trim();
        if (TextUtils.isEmpty(searchkey)) {
            isSearchMode = false;
            mListBeanSearch = null;
            setListView();
            text_allapp.setVisibility(View.VISIBLE);
            text_myapp.setVisibility(View.VISIBLE);
        } else {
            isSearchMode = true;
            LogUtil.i("search-->" + mListBeanOrg.getList().size());
            mListBeanSearch = mListBeanOrg.searchByName(searchkey);
            LogUtil.i("search-mListBeanSearch->" + mListBeanSearch.getList().size());
            setListView();
            text_allapp.setVisibility(View.GONE);
            text_myapp.setVisibility(View.GONE);
            scrollView.scrollTo(0, 0);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        getWarnUnReadCount();
    }

    private void setListView() {
        if (mAdapter == null) {
            mAdapter = new MyAdapterList();
            mRecyclerView.setAdapter(mAdapter);
        } else {
            mAdapter.notifyDataSetChanged();
        }
        if (mAdapterSmall == null) {
            mAdapterSmall = new MyAdapterListSmall();
            recyclerview_small.setAdapter(mAdapterSmall);
        } else {
            mAdapterSmall.notifyDataSetChanged();
        }


        if (isSearchMode) {
            recyclerview_all.setVisibility(View.GONE);
            recyclerview_small.setVisibility(View.GONE);
            mRecyclerView.setVisibility(View.VISIBLE);
            view_bottom_text_zone.setVisibility(View.GONE);
        } else {

            if (isSpand) {
                recyclerview_small.setVisibility(View.GONE);
                mRecyclerView.setVisibility(View.VISIBLE);
            } else {
                recyclerview_small.setVisibility(View.VISIBLE);
                mRecyclerView.setVisibility(View.GONE);
            }

            recyclerview_all.setVisibility(View.VISIBLE);
            view_bottom_text_zone.setVisibility(View.VISIBLE);

            if (mAdapterAllList == null) {
                mAdapterAllList = new AppAllListAdapterList();
                recyclerview_all.setAdapter(mAdapterAllList);
            } else {
                mAdapterAllList.notifyDataSetChanged();
            }
        }
    }


    private void getListMine() {
        MyParams params = new MyParams();
        showProgress();
        params.put("projectNo", Constants.PROJECT_NO);
        MyHttpUtils.post(Constants.URL_HOME_APP_MODULE, params, new MyHttpListener() {
                    @Override
                    public void onSuccess(int httpWhat, Object result) {
                        mListBean = (HomeGrideListBean) result;
                        mListBean.processData();
//                        mListBeanOrg = mListBean.copy();
                        setWarnUnRead();
                        setListView();
                    }

                    @Override
                    public void onFailure(int httpWhat, Object result) {
                        super.onFailure(httpWhat, result);
//            mListBean = new ServiceNewListBean();
                    }

                    @Override
                    public void onFinish(int httpWhat) {
                        dismissProgress();
                        getListAll();
                    }
                },
                0, HomeGrideListBean.class);

    }

    private void getListAll() {

        MyParams params = new MyParams();
        showProgress();
        params.put("projectNo", Constants.PROJECT_NO);
        MyHttpUtils.post(Constants.URL_USER_AUTHORITY_APP, params, new MyHttpListener() {
                    @Override
                    public void onSuccess(int httpWhat, Object result) {
                        mListBeanOrg = (HomeGrideListBean) result;
                        mListBeanOrg.processData();
                        LogUtil.i("onSuccess-->" + mListBeanOrg.getList().size());
//                       mGroupListBean = mListBeanOrg.processGroupListBean(mListBean);
                        mGroupListBean = mListBeanOrg.processGroupListBean(null);
                        LogUtil.i("onSuccess-mGroupListBean.size---->" + mGroupListBean.getList().size());
                        setListView();
                    }

                    @Override
                    public void onFailure(int httpWhat, Object result) {
                        super.onFailure(httpWhat, result);
//            mListBean = new ServiceNewListBean();
                    }

                    @Override
                    public void onFinish(int httpWhat) {
                        dismissProgress();
                    }
                },
                0, HomeGrideListBean.class);

    }

    ItemTouchHelper.Callback
            mItemTouchCallBack = new ItemTouchHelper.Callback() {
        /**
         * 设置滑动类型标记
         *
         * @param recyclerView
         * @param viewHolder
         * @return
         *          返回一个整数类型的标识，用于判断Item那种移动行为是允许的
         */
        @Override
        public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
            return makeMovementFlags(ItemTouchHelper.RIGHT | ItemTouchHelper.LEFT | ItemTouchHelper.DOWN | ItemTouchHelper.UP, 0);
        }

        /**
         * Item是否支持长按拖动
         *
         * @return
         *          true  支持长按操作
         *          false 不支持长按操作
         */
        @Override
        public boolean isLongPressDragEnabled() {
            if (isSearchMode) return false;
            return true;
        }

        /**
         * Item是否支持滑动
         *
         * @return
         *          true  支持滑动操作
         *          false 不支持滑动操作
         */
        @Override
        public boolean isItemViewSwipeEnabled() {
            return false;
        }

        @Override
        public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {

        }

        /**
         * 拖拽切换Item的回调
         *
         * @param recyclerView
         * @param viewHolder
         * @param target
         * @return
         *          如果Item切换了位置，返回true；反之，返回false
         */
        @Override
        public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {


            //得到当拖拽的viewHolder的Position
            int fromPosition = viewHolder.getAdapterPosition();
            //拿到当前拖拽到的item的viewHolder
            int toPosition = target.getAdapterPosition();
            if (fromPosition < toPosition) {
                for (int i = fromPosition; i < toPosition; i++) {
                    Collections.swap(mListBean.getList(), i, i + 1);
                }
            } else {
                for (int i = fromPosition; i > toPosition; i--) {
                    Collections.swap(mListBean.getList(), i, i - 1);
                }
            }
            mAdapter.notifyItemMoved(viewHolder.getAdapterPosition(), target.getAdapterPosition());
            return true;
        }

        /**
         * Item被选中时候回调
         *
         * @param viewHolder
         * @param actionState
         *          当前Item的状态
         *          ItemTouchHelper.ACTION_STATE_IDLE   闲置状态
         *          ItemTouchHelper.ACTION_STATE_SWIPE  滑动中状态
         *          ItemTouchHelper#ACTION_STATE_DRAG   拖拽中状态
         */
        @Override
        public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
            //  item被选中的操作
            if (actionState != ItemTouchHelper.ACTION_STATE_IDLE) {
//                viewHolder.itemView.setBackgroundResource(R.color.md_gray);
                isEditMode = true;
                setEditView();
            }
            super.onSelectedChanged(viewHolder, actionState);
        }

        /**
         * 用户操作完毕或者动画完毕后会被调用
         *
         * @param recyclerView
         * @param viewHolder
         */
        @Override
        public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
            // 操作完毕后恢复颜色
//            viewHolder.itemView.setBackgroundResource(R.drawable.md_common_bg);
//            isEditMode = false;
//            setEditView();
            super.clearView(recyclerView, viewHolder);
        }
    };

    void setEditView() {
        if (isEditMode) {
            setTitleRightText("保存", new View.OnClickListener() {
                @Override
                public void onClick(View v) {
//                    showToast("保存"+mListBean.getList().get(7).getName());
                    onSaveClick();
                }
            });
            setTitleLeftText("取消", new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    isEditMode = false;
//                    mAdapter.notifyDataSetChanged();
                    mListBeanSearch = mListBeanOrg.copy();
                    setEditView();
                    getListMine();
                }
            });
            findViewById(R.id.base_btn_back).setVisibility(View.GONE);
            mGroupListBean = mListBeanOrg.processGroupListBean(mListBean);
        } else {
            setTitleLeftButton(null);
            findViewById(R.id.base_title_left_text).setVisibility(View.GONE);
            findViewById(R.id.base_title_right_text).setVisibility(View.GONE);
            mGroupListBean = mListBeanOrg.processGroupListBean(null);
        }
        setListView();
    }

    void onSaveClick() {
        MyParams params = new MyParams();
        showProgress();
        params.putObj("moduleUserConfig", mListBean.getPostJsonArray());
        params.put("projectNo", Constants.PROJECT_NO);
        MyHttpUtils.post(Constants.URL_HOME_APP_CUSTOM_ORDER, params, new MyHttpListener() {
                    @Override
                    public void onSuccess(int httpWhat, Object result) {
                        DialogUtils.DialogOkMsg(mContext, ((BasisBean) result).getStatusInfo());
//                        mListBeanOrg = mListBean.copy();
                        mListBeanSearch = mListBeanOrg.copy();
                        isEditMode = false;
                        setEditView();
                        setResult(Activity.RESULT_OK);
                    }

                    @Override
                    public void onFailure(int httpWhat, Object result) {
                        super.onFailure(httpWhat, result);
//            mListBean = new ServiceNewListBean();
                    }

                    @Override
                    public void onFinish(int httpWhat) {
                        dismissProgress();
                    }
                },
                0, BasisBean.class);
    }

    public class MyAdapterList extends RecyclerView.Adapter<MyAdapterList.ViewHolder> {


        public MyAdapterList() {
        }

        //创建新View，被LayoutManager所调用
        @Override
        public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
            View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.home_enter_grid_item, viewGroup, false);
            return new ViewHolder(view);
        }


        //将数据与界面进行绑定的操作
        @Override
        public void onBindViewHolder(ViewHolder viewHolder, int position) {
            viewHolder.bind(position);
        }

        //获取数据的数量
        @Override
        public int getItemCount() {
            if (isSearchMode) {
                return mListBeanSearch == null ? 0 : mListBeanSearch.getList().size();
            } else {
                if(isEditMode){
                    return mListBean == null ? 0 : mListBean.getList().size();
                }else {
                    return mListBean == null ? 0 : mListBean.getList().size() + 1;
                }
            }

        }

        //自定义的ViewHolder，持有每个Item的的所有界面元素
        public class ViewHolder extends RecyclerView.ViewHolder {
            @BindView(R.id.list_item)
            public View list_item;
            @BindView(R.id.text_name)
            public TextView text_name;
            @BindView(R.id.img_icon)
            public ImageView img_icon;
            @BindView(R.id.img_adddelete)
            public ImageView img_adddelete;
            @BindView(R.id.text_count)
            public TextView text_count;

            public ViewHolder(View view) {
                super(view);
                ButterKnife.bind(this, view);
                img_adddelete.setImageResource(R.drawable.home_app_img_del);
            }

            public void bind(int position) {
                HomeGrideListData data = null;
                if (isSearchMode) {
                    data = mListBeanSearch.getList().get(position);
                    img_adddelete.setVisibility(View.INVISIBLE);
                } else {
                    if ( !isEditMode && position == (getItemCount() - 1)) {
                        img_adddelete.setVisibility(View.INVISIBLE);
                        img_icon.setImageResource(R.drawable.home_app_icon_arrow_up);
                        text_count.setVisibility(View.INVISIBLE);
                        text_name.setText("收起");
                        list_item.setTag(position);
                        return;
                    } else {
                        data = mListBean.getList().get(position);
                        img_adddelete.setVisibility(isEditMode ? View.VISIBLE : View.INVISIBLE);
                    }

                }

                if (isEditMode) {
                    text_count.setVisibility(View.GONE);
                } else {
                    if (!TextUtils.isEmpty(data.getUnReadCountMsg())) {
                        text_count.setVisibility(View.VISIBLE);
//                        text_count.setText(data.getUnReadCountMsg()+"");
                    } else {
                        text_count.setVisibility(View.GONE);
                    }
                }

//                LogUtil.i("isSearchMode-------?"+isSearchMode);
//                LogUtil.i("isEditMode-------?"+isEditMode);
                text_name.setText(data.getName());
                BasisApp.loadImg(mContext, data.getIconUrl(), img_icon, R.drawable.base_img_default_square);
                img_adddelete.setTag(position);
                list_item.setTag(position);
            }

            @OnClick(R.id.list_item)
            public void onItemClick(View v) {
                int position = (int) v.getTag();
                if(!isEditMode &&  (position == (getItemCount() - 1))){
                    isSpand = false;
                    setListView();
                    return;
                }
                if (isEditMode) return;
                HomeGrideListData data;
                if (isSearchMode) {
                    data = mListBeanSearch.getList().get(position);
                } else {
                    data = mListBean.getList().get(position);
                }
                data.onItemClick(mContext);
            }

            @OnClick(R.id.img_adddelete)
            public void onAddDeleteClick(View v) {
                if (!isEditMode) return;
                int position = (int) v.getTag();
                HomeGrideListData data = mListBean.getList().get(position);
                if (mListBean.getList().size() <= 1) {
//                    showToast("订阅应用数量只有1个，不可再减少");
                } else {
                    mListBean.getList().remove(data);
                    mGroupListBean.addHomeGridData(data);
                    setListView();
                }
            }
        }
    }

    public class MyAdapterListSmall extends RecyclerView.Adapter<MyAdapterListSmall.ViewHolder> {


        public static final int MAX_SHOW = 6;

        public MyAdapterListSmall() {
        }

        //创建新View，被LayoutManager所调用
        @Override
        public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
            View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.home_app_small_grid_item, viewGroup, false);
            return new ViewHolder(view);
        }


        //将数据与界面进行绑定的操作
        @Override
        public void onBindViewHolder(ViewHolder viewHolder, int position) {
            viewHolder.bind(position);
        }

        //获取数据的数量
        @Override
        public int getItemCount() {
            if (mListBean == null) return 1;
            if (mListBean.getList().size() > MAX_SHOW) return MAX_SHOW + 1;
            return mListBean.getList().size() + 1;
        }

        //自定义的ViewHolder，持有每个Item的的所有界面元素
        public class ViewHolder extends RecyclerView.ViewHolder {
            @BindView(R.id.list_item)
            public View list_item;
            @BindView(R.id.img_icon)
            public ImageView img_icon;

            public ViewHolder(View view) {
                super(view);
                ButterKnife.bind(this, view);
            }

            public void bind(int position) {
                HomeGrideListData data;
                if (position == getItemCount() - 1) {
                    img_icon.setVisibility(View.INVISIBLE);
                    list_item.setBackgroundResource(R.drawable.home_app_icon_smll_more);
                } else {
                    img_icon.setVisibility(View.VISIBLE);
                    data = mListBean.getList().get(position);
                    list_item.setBackgroundResource(R.drawable.home_app_small_bg);
                    BasisApp.loadImg(mContext, data.getIconUrl(), img_icon, R.drawable.base_img_default_square);
                }

                list_item.setTag(position);
            }

            @OnClick(R.id.list_item)
            public void onItemClick(View v) {
//                if(isEditMode)return;
                int position = (int) v.getTag();
                if (position == getItemCount() - 1) {
                    isSpand = true;
                    setListView();
                }
            }

        }
    }

    public class AppGridAdapterList extends RecyclerView.Adapter<AppGridAdapterList.ViewHolder> {

        HomeGrideListBean homeGrideListBean;

        public AppGridAdapterList(HomeGrideListBean listBean) {
            homeGrideListBean = listBean;
        }

        public void setData(HomeGrideListBean listBean) {
            homeGrideListBean = listBean;
            notifyDataSetChanged();
        }

        //创建新View，被LayoutManager所调用
        @Override
        public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
            View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.home_enter_grid_item, viewGroup, false);
            return new ViewHolder(view);
        }


        //将数据与界面进行绑定的操作
        @Override
        public void onBindViewHolder(ViewHolder viewHolder, int position) {
            viewHolder.bind(position);
        }

        //获取数据的数量
        @Override
        public int getItemCount() {
            return mListBean == null ? 0 : homeGrideListBean.getList().size();
        }

        //自定义的ViewHolder，持有每个Item的的所有界面元素
        public class ViewHolder extends RecyclerView.ViewHolder {
            @BindView(R.id.list_item)
            public View list_item;
            @BindView(R.id.text_name)
            public TextView text_name;
            @BindView(R.id.img_icon)
            public ImageView img_icon;
            @BindView(R.id.img_adddelete)
            public ImageView img_adddelete;

            public ViewHolder(View view) {
                super(view);
                ButterKnife.bind(this, view);
                img_adddelete.setImageResource(R.drawable.home_app_img_add);
            }

            public void bind(int position) {
                HomeGrideListData data = homeGrideListBean.getList().get(position);
                text_name.setText(data.getName());
                BasisApp.loadImg(mContext, data.getIconUrl(), img_icon, R.drawable.base_img_default_square);
                img_adddelete.setVisibility(isEditMode ? View.VISIBLE : View.INVISIBLE);
                list_item.setTag(position);
                img_adddelete.setTag(position);
            }

            @OnClick(R.id.list_item)
            public void onItemClick(View v) {
                if (isEditMode) return;
                int position = (int) v.getTag();
                HomeGrideListData data = homeGrideListBean.getList().get(position);
                data.onItemClick(mContext);
            }

            @OnClick(R.id.img_adddelete)
            public void onAddDeleteClick(View v) {
                if (!isEditMode) return;
                int position = (int) v.getTag();
                HomeGrideListData data = homeGrideListBean.getList().get(position);
                if (mListBean.getList().size() >= (HomeGrideListBean.MAX_SHOW - 1)) {
//                    showToast("已加满9个，不可再添加");
                } else {
                    mListBean.getList().add(data);
                    mGroupListBean.removeGridData(data);
                    setListView();
                }

            }
        }
    }


    public class AppAllListAdapterList extends RecyclerView.Adapter<AppAllListAdapterList.ViewHolder> {

        public AppAllListAdapterList() {
        }

        //创建新View，被LayoutManager所调用
        @Override
        public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
            View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.home_app_all_list_item, viewGroup, false);
            return new ViewHolder(view);
        }


        //将数据与界面进行绑定的操作
        @Override
        public void onBindViewHolder(ViewHolder viewHolder, int position) {
            viewHolder.bind(position);
        }

        //获取数据的数量
        @Override
        public int getItemCount() {
            return mGroupListBean == null ? 0 : mGroupListBean.getList().size();
        }

        //自定义的ViewHolder，持有每个Item的的所有界面元素
        public class ViewHolder extends RecyclerView.ViewHolder {
            @BindView(R.id.list_item)
            public View list_item;
            @BindView(R.id.text_title)
            public TextView text_title;
            @BindView(R.id.recyclerview)
            public RecyclerView recyclerview;

            public AppGridAdapterList adapter;

            public ViewHolder(View view) {
                super(view);
                ButterKnife.bind(this, view);

                recyclerview.setLayoutManager(new GridLayoutManager(mContext, 5));
                adapter = new AppGridAdapterList(null);
                recyclerview.setAdapter(adapter);
            }

            public void bind(int position) {
                HomeGrideListBean data = mGroupListBean.getList().get(position);
                text_title.setText(data.getTitle());
                adapter.setData(data);
            }

        }
    }

    BasisBean mWarnUnReadCount;

    private void getWarnUnReadCount() {
        MyParams params = new MyParams();
        MyHttpUtils.post(Constants.URL_WARN_GET_UNREAD_COUNT, params, new MyHttpListener() {
                    @Override
                    public void onSuccess(int httpWhat, Object result) {
                        if (isFinishing()) return;
                        mWarnUnReadCount = (BasisBean) result;
                        setWarnUnRead();
                    }

                    @Override
                    public void onFailure(int httpWhat, Object result) {
//                        super.onFailure(httpWhat, result);
                        mWarnUnReadCount = new BasisBean();
                        mWarnUnReadCount.setResultData("0");
                        setWarnUnRead();
                    }

                    @Override
                    public void onFinish(int httpWhat) {
//                        dismissProgress();
                    }
                },
                0, BasisBean.class);

    }

    void setWarnUnRead() {
        if (mWarnUnReadCount == null) return;
        if (mListBean == null) return;
        mListBean.setWarnUnReadCount(Integer.valueOf(mWarnUnReadCount.getResultData()));
        if (mAdapter != null) {
            mAdapter.notifyDataSetChanged();
        }
    }


    public class ItemLeftDecoration extends RecyclerView.ItemDecoration {

        private int space;

        public ItemLeftDecoration(int space) {
            this.space = space;
        }

        @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            if (parent.getChildLayoutPosition(view)!=0){
                outRect.left = space;
            }
        }
    }

}
